<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Untitled Document</title>
    </head>
    <body>
        <div id='df' style='position:absolute;left:100px;top:50px;width:200px;height:200px;background-color:#fc0;'>
            <div id='dd' style="position:relative; overflow-y:scroll; height:100px;top:50px;">
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                <br/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button onclick="getAbsPos(this,$('df'))">               pos                </button>
            </div>
        </div>
    </body>
</html>
<script type="text/javascript" src="BTO.js">
</script>
<script type='text/javascript'>
    var jQuery = {}
	jQuery.fn ={};
    jQuery.fn.offset = function(){
        if (!this[0])         
            return {
                top: 0,
                left: 0
            };
        if (this[0] === this[0].ownerDocument.body)         
            return jQuery.offset.bodyOffset(this[0]);
        var box = this[0].getBoundingClientRect(),
			doc = this[0].ownerDocument,
			body = doc.body,
			docElem = doc.documentElement,
			clientTop = docElem.clientTop || body.clientTop || 0,
			clientLeft = docElem.clientLeft || body.clientLeft || 0,
			top = box.top + (self.pageYOffset || jQuery.boxModel && docElem.scrollTop || body.scrollTop) - clientTop,
			left = box.left + (self.pageXOffset || jQuery.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
        return {
            top: top,
            left: left
        };
    };
    
    
    function getAbsPos(obj, offsetObj){
        var offsetObj = offsetObj || document;
        var curPos = {
            x: 0,
            y: 0
        };
        if (obj.offsetParent) {
            while (obj.offsetParent && obj != offsetObj) {
                curPos.x += obj.offsetLeft - obj.scrollLeft;
                curPos.y += obj.offsetTop - obj.scrollTop;
                obj = obj.offsetParent;
            }
        } else if (obj.x) {
            curPos.x += obj.offsetLeft - obj.scrollLeft;
            curPos.y += obj.offsetTop - obj.scrollTop;
        }
        
        /*obj = obj2;
        if (obj.offsetParent) {
            while (obj.offsetParent && obj.offsetParent != offsetObj) {
                curPos.x -= obj.scrollLeft;
                curPos.y -= obj.scrollTop;
                obj = obj.parentNode;
            }
        } else if (obj.x) {
            curPos.x -= obj.scrollLeft;
            curPos.y -= obj.scrollTop;
        }
        
        console.log(curPos.x + ' ');
        console.log(curPos.y + ',');*/
    }
</script>
